local skel = fk.CreateSkill {
  name = "lb__fanlie",
}

Fk:loadTranslationTable {
  ["lb__fanlie"] = "繁裂",
  [":lb__fanlie"] = "当你进入濒死状态时，你可以失去一个技能以回复1点体力，然后你摸剩余技能数张牌。",

  ["#lb__fanlie"] = "繁裂：你可以失去一个技能以回复1点体力，然后摸剩余技能数张牌",
  ["#lb__fanlie_lose"] = "繁裂：你可以失去%arg以回复1点体力",

  ["$lb__fanlie1"] = "",
  ["$lb__fanlie2"] = "",
}

skel:addEffect(fk.EnterDying, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and target:isAlive()
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local list = player:getSkillNameList()
    if #list > 0 then
      if #list > 1 then
        table.insert(list, "Cancel")
        local choice = room:askToChoice(player, {
          choices = list,
          prompt = "#lb__fanlie",
          skill_name = skel.name,
        })
        event:setCostData(self, {name = choice})
        return choice ~= "Cancel"
      else
        event:setCostData(self, {name = list[1]})
        return player.room:askToSkillInvoke(player, {skill_name = skel.name, prompt = "#lb__fanlie_lose::"..list[1],})
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:handleAddLoseSkills(player, "-"..event:getCostData(self).name)
    if player:isAlive() and player:isWounded() then
      room:recover{
        who = player,
        num = 1,
        skillName = skel.name,
        recoverBy = player,
      }
    end
    local num = #player:getSkillNameList()
    if player:isAlive() and num > 0 then
      player:drawCards(num, skel.name)
    end
  end,
})

return skel